#!/bin/sh

: ${NOTEBOOK_DIR:=/home/jovyan}
: ${NB_PREFIX:=""}


if [ ! -z "${GIT_CLONE_REPO}" ]; then
    REPO_NAME=$(basename "${GIT_CLONE_REPO}" .git)
    
    pushd "${NOTEBOOK_DIR}"
    
    if [ -d "${REPO_NAME}" ]; then
        echo "The repository ${REPO_NAME} already exists in ${NOTEBOOK_DIR}."
        echo "Skipping cloning."
    else
        echo "Cloning repository ${GIT_CLONE_REPO} into ${NOTEBOOK_DIR}"
        git clone -j $(nproc) "${GIT_CLONE_REPO}"
    fi
    popd
fi


jupyter lab \
    --notebook-dir=${NOTEBOOK_DIR} \
    --ip=0.0.0.0 \
    --no-browser \
    --allow-root \
    --port=8888 \
    --IdentityProvider.token='' \
    --ServerApp.password='' \
    --ServerApp.base_url=${NB_PREFIX} \
    --ServerApp.disable_check_xsrf=True \
    --ServerApp.terminado_settings="{'shell_command':['/bin/bash']}" \
    --ServerApp.allow_origin='*' \
    --FileContentsManager.delete_to_trash=True \
    --ResourceUseDisplay.track_cpu_percent=True